package avicit.bdp.dcs.plugin.kafka;

import avicit.bdp.dcs.plugin.BaseDataxParam;
import avicit.bdp.dcs.plugin.DataxConstants;
import avicit.bdp.dcs.plugin.DataxJsonInterface;
import avicit.bdp.dcs.plugin.kafka.param.KafkaDataxParam;

import java.util.HashMap;
import java.util.Map;

/**
 * @金航数码科技有限责任公司
 * @作者：liyb
 * @邮箱：liyb@avic-digital.com
 * @创建时间： 2020-08-01 11:39
 * @类说明：
 * @修改记录：
 */
public class KafkaDataxJson implements DataxJsonInterface {

    /**
     * 获取Reader插件名称
     * @return
     */
    @Override
    public String getReaderName() {
        return DataxConstants.KAFKA_READER;
    }

    /**
     * 获取Writer插件名称
     * @return
     */
    @Override
    public String getWriterName() {
        return null;
    }

    @Override
    public Map<String, Object> buildReader(BaseDataxParam param) {
        KafkaDataxParam dataxParam = (KafkaDataxParam) param;

        Map<String, Object> readerObj = new HashMap<>(4);
        readerObj.put(DataxConstants.NAME, getReaderName());
        Map<String, Object> parameterObj = new HashMap<>(8);
        parameterObj.put(DataxConstants.KAFKA_TOPIC, dataxParam.getKafkaTopic());
        parameterObj.put(DataxConstants.KAFKA_SERVERS, dataxParam.getBootstrapServers());
        parameterObj.put(DataxConstants.KAFKA_PARTITIONS, dataxParam.getKafkaPartitions());
        parameterObj.put(DataxConstants.KAFKA_MSGID, dataxParam.getMsgId());
        parameterObj.put(DataxConstants.KAFKA_MSG_SERIALIZE_TYPE, dataxParam.getMsgSerializeType());
        parameterObj.put(DataxConstants.KAFKA_COMPANY, DataxConstants.KAFKA_DEFAULT);
        parameterObj.put(DataxConstants.KAFKA_GROUP_ID, dataxParam.getGroupId());
        parameterObj.put(DataxConstants.KAFKA_AUTO_OFFSET_REST, dataxParam.getAutoOffestRest());
        parameterObj.put(DataxConstants.KAFKA_PARAS, dataxParam.getParas());
        readerObj.put(DataxConstants.PARAMETER, parameterObj);
        return readerObj;
    }

    @Override
    public Map<String, Object> buildWriter(BaseDataxParam param) {
        return null;
    }

}
